package common

import "sync"

type Command struct {
	DeviceID  string
	Method    string
	Params    map[string]interface{}
	MessageID string
}
type Result struct {
	Result  int    `json:"result"`
	Number  int    `json:"number"`
	ErrCode string `json:"errcode"`
	Message string `json:"message"`
	Ts      int64  `json:"ts"`
	Method  string `json:"method"`
}

const QueueSize = 20

// DeviceCommandQueue 结构用于存储每个设备的命令队列
type DeviceCommandQueue struct {
	mu     sync.RWMutex
	queues map[string]chan Command
}

// 全局变量，用于存储所有设备的命令队列
var CommandQueues = &DeviceCommandQueue{
	queues: make(map[string]chan Command),
}

// getQueue 获取指定设备的队列，如果不存在则创建
func (dcq *DeviceCommandQueue) GetQueue(deviceID string) chan Command {
	dcq.mu.Lock()
	defer dcq.mu.Unlock()

	if q, exists := dcq.queues[deviceID]; exists {
		return q
	}

	q := make(chan Command, QueueSize)
	dcq.queues[deviceID] = q
	return q
}
